package com.open.base.config;

import com.open.base.interceptor.PermissionInterceptor;
import com.open.base.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * 拦截器配置
 * @author dashu03
 * @date 2025年04月15日 11:02
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Resource
    private TokenInterceptor tokenInterceptor;

    @Resource
    private PermissionInterceptor permissionInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        // token拦截器
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")
                .order(1);

        // 权限拦截器
        registry.addInterceptor(permissionInterceptor)
                .excludePathPatterns("/") // 添加排除模式
                .excludePathPatterns("/checkCode") // 添加排除模式
                .excludePathPatterns("/login") // 添加排除模式
                .excludePathPatterns("/logout") // 添加排除模式
                .excludePathPatterns("/register") // 添加排除模式
                .excludePathPatterns("/system/config/getSystemConfig") // 添加排除模式
                .addPathPatterns("/**")
                .order(2);
    }

}